package com.neusoft.myDemo.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.neusoft.myDemo.dao.UserDao;
import com.neusoft.myDemo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    public Map<String,Object> userMapList(HttpServletRequest request, User user){
        PageHelper.startPage(request);
        Map<String,Object> m = new HashMap<>();
        Page users = (Page) userDao.queryInfo(user);
        m.put("msg","调试成功");
        m.put("code","0");
        m.put("data",users.getResult());
        m.put("count",users.getTotal());
        return m;

    }

    public int addAndUpdataUsers(User user){
        if (StringUtils.isEmpty(user.getId())){
            return userDao.addUsers(user);
        }else {
            return userDao.updataUsers(user);
        }

    }
}
